// auteur: MyRLinkedList //recursieve versie
// J.Kaldeway

class RListNode<E>
{
    E data_;
    RListNode<E> next_;
        
    RListNode(E data, RListNode<E> next)
    {
        data_ = data;
        next_ = next;
    }
        
    void addLast(E e)
    {
        if (next_ == null)
            next_ = new RListNode<E>(e,null);
        else
            next_.addLast(e);
    }

    void delete(E e)
    {
        if (next_ != null) 
        {
        	if (next_.data_.equals(e))
               next_ = next_.next_;
            else 
               next_.delete(e);  
        }
    }

    @Override
	public String toString()
    {
        return data_.toString();
    }
    
    public String toString2()
    {
        String s = data_.toString();
        if (next_ != null)
        {
        	s = s + " -> " + next_.toString2();
        }
        return s;
    }
}

public class MyRLinkedList<E>
{
    private RListNode<E> head_ = null;
    
    public void addLast(E e)
    {
        if (head_ == null)
            head_ = new RListNode<E>(e,null);
        else
            head_.addLast(e);
    }
        
    public void delete(E e)
    {
        if (head_ != null)
        {
            if (head_.data_.equals(e))
            	head_ = head_.next_;
            else 
               	head_.delete(e);  
        }
    }

    @Override
	public String toString()
    {
        if (head_ == null)
           return "";
        else
           return head_.toString2();  
    }
    
    public static void main(String[] s)
    {
        MyRLinkedList<Integer> list = new MyRLinkedList<Integer>();
        System.out.println(list);
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        System.out.println(list);
        list.delete(2);
        System.out.println(list);
        list.delete(1);
        System.out.println(list);
        list.delete(3);
        System.out.println(list);
    }
}